<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       #top{
        position: fixed;
        bottom: 100px;
       }
       .cn{ 
        width: 200px;
        height: 200px;
        margin: 50px auto;
        } 
       .box1{
        line-height: 200px;
        text-align: center;
        color: red;
        border: 1px solid blue;
        font-size: 50px;
       }
       #but{
        width: 200px;
        height: 50px;
        font-size: 30px;
        border: 1px solid blue;
        background-color: black;
        color: #fff;
       }
    </style>
</head>
<body style="height: 2000px;">
    <input type="button" id="top" value="回到顶部">
    <div class="cn">
        <div class="box1">10</div>
        <input type="button" id="but" value="开始">
    </div>
</body>
<script>
    // 1. 回到顶部
    var top = document.querySelector("#top");
    top.onclick= function(){
           document.documentElement.scrollTop = 0 ; 
    }
    
    // 2. 倒计时(三个按钮，先实现基本功能，不用控制按钮的禁用)
    var box1 = document.getElementsByClassName('box1')[0];
    var but = document.getElementById('but')
    var t
    var i = 0;
    var s = box1.innerHTML;
    but.onclick = function(){
        if(i === 0){
            start();
            i = 1;
        }else if(i === 1){
            stop();
            i = 0;
        }else{
            reset();
            i = 0;
        } 
    }






    function reset(){
        box1.innerHTML = s;
        but.value = "开始";
    }
    function stop(){
        clearInterval(t);
        but.value = "继续";
    }
    function start(){
        clearInterval (t);
       t = setInterval(function(){
        if( box1.innerHTML <= 1 ){
            clearInterval (t);
            box1.innerHTML = "结束了"
            i = 2 
            but.value = '复位'
        }else{
            box1.innerHTML--
        }
       },1000 )
       but.value ="暂停"
    }

</script>
</html>